home *** CD-ROM | disk | FTP | other *** search
- Path: hubcap.clemson.edu!hubcap!mjs
- From: mjs@hubcap.clemson.edu (M. J. Saltzman)
- Newsgroups: comp.lang.c
- Subject: Re: do || die;
- Date: 7 Mar 96 17:07:46 GMT
- Organization: Clemson University
- Message-ID: <mjs.826218466@hubcap>
- References: <1996Mar7.052636.59812@ucl.ac.uk> <DnwJKs.KyJ@uns.bris.ac.uk>
- NNTP-Posting-Host: hubcap.clemson.edu
- X-Newsreader: NN version 6.5.0 #1
-
- nathan@pact.srf.ac.uk (Nathan Sidwell) writes:
-
- >Timothy Slidel (slidel@bsm.bioc.ucl.ac.uk) wrote:
- >: Whilst it seems to work ok - is it considered bad style to use
- >: logical operator expressions as conditional statements on their own, a la
- >: Perl?
-
- >: e.g. if I want to decrement i only when it is != 0:
-
- >: i && i--;
-
- >You should write to make your intent clear.
-
- One advantage that the original version has is that it is an expression,
- so can be used more flexibly if made into a macro. Still, the intent
- might be clearer with
-
- i ? i-- : i
-
- One difference between these two versions as macros is the number of
- times the argument is evaluated.
-
- Note that if the expression is made into a statement in its own right,
- the compiler is technically correct (if somewhat pedantic--after all,
- there is a side effect) to note that the value of the expression is
- never used. There are many ways to write it so as to avoid this
- problem, e.g.,
-
- i -= i != 0
-
- (which is probably what I would have written).
- --
- Matthew Saltzman
- Clemson University Math Sciences
- mjs@clemson.edu
-